<template>
  <div class="page-container">
    <page_breadcrumb
      :getKeyMethod="init_table_model"
      @change="change_table_model"
      pageOption
    />
    <ex_super_table_page v-bind="option" @selection-change="e => selection = e" ref="SuperTablePage">
      <template v-slot:action-right>
        <el-upload ref="upload" :show-file-list="false" action="/oms-api/purchase/OmsPurchaseSupplierRpc/importExcel.json"
          v-auth="'oms_return_good_confirm_import'" style="display: inline;" :on-success="uploadExcelSuccess"
          :on-error="uploadExcelError">
          <el-button slot="trigger" style="margin-left: 10px;" size="mini">{{ $tt('label_import_supplier') }}</el-button>
        </el-upload>
      </template>
    </ex_super_table_page>
  </div>
</template>
<script>
// import business_function from "@/common/business_function"
import superTablePageFunction from "@/mixin/super-table-page-function";
import page_table_model_manage from "@/mixin/page_table_model_manage";
import emitOnFunction from "@/mixin/emit-on-function";
let emitKey = "oms>purchase>supplyManage>supplier_manage";

import select_file_temp from "@/component/base/select_file_temp";

export default {
  title: "label_purchase_supplier_good_manage",
  mixins: [
    superTablePageFunction,
    emitOnFunction(emitKey),
    page_table_model_manage,
  ],
  components: {},
  data() {
    return {
      option: {
        search: {
          model: [
            { label: "label_customer", key: "customerId", type: 'common_customer_choose' },
            {
              label: "label_supplier_good_name",
              key: "supplierName",
            },
            {
              label: "label_contact",
              key: "contacter",
            },
            {
              label: "label_contact_phone",
              key: "contacterPhone",
            },
            {
              label: "label_platform_type",
              key: "platformType",
              type: "select",
              enum: "PurchasePlatformTypeEnum",
            },
            {
              label: "label_settlement_method",
              key: "settleMethod",
              type: "select",
              enum: "SupplierSettleMethodEnum",
            },
          ],
        },
        action: [
          {
            label: "label_add_supplier",
            attrs: { icon: "el-icon-plus" },
            auth: "oms_purchase_supplier_edit",
            click: () => {
              this.$router.push({
                path: "/page/oms/purchase/supplyManage/supplier_operation",
                query: { emitKey },
              });
            },
          },
        ],
        actionExtra: [
          {
            label: "label_export",
            auth: "oms_purchase_supplier_edit",
            click: this.exportExcel,
          },
          {
            // label: 'label_download_import_template',
            auth: "oms_purchase_supplier_edit",
            render: (h, { data, item }) => {
              return h(select_file_temp, {
                props: {
                  service: "OMS",
                  module: "PURCHASE_SUPPLIER",
                  label: this.$tt("label_download_import_template"),
                },
              });
            },
          },
          // {
          //   label: "label_import_supplier",
          //   auth: "oms_purchase_supplier_edit",
          //   click: () => {},
          // },
        ],

        table: {
          url: "/oms-api/purchase/OmsPurchaseSupplierRpc/selectPage.json",
          attrs: {},
          model: this.init_table_model(),
        },
      },
    };
  },
  methods: {
    option_table_model() {
      return [
        {
          type: "selection",
          clickToggle: true,
          keyGroup: "label_table_operate",
        },
        {
          key: "supplierName",
          label: "label_supplier_good_name",
          "min-width": 130,
          "show-overflow-tooltip": true,
        },
        {
          key: "customerName",
          label: "label_tms_track_customer_name",
          "min-width": 130,
          "show-overflow-tooltip": true,
        },
        {
          key: "supplierOnlyCode",
          label: "label_supplier_vendor_unique_code",
          "min-width": 180,
        },
        {
          key: "settleMethod",
          label: "label_settlement_method",
          width: 100,
          "show-overflow-tooltip": true,
          formatter: (r, c, v, i) =>
            this.$enumShow(v, "SupplierSettleMethodEnum"),
        },

        {
          key: "delayRate",
          label: "label_supplier_delay_rate",
          width: 110,
          formatter: (r, c, v, i) => (v ? this.$addUnit(v, "%") : "-"),
        },
        {
          key: "replenishRate",
          label: "label_supplier_replenishment_rate",
          width: 110,
          formatter: (r, c, v, i) => (v ? this.$addUnit(v, "%") : "-"),
        },
        {
          key: "returnRate",
          label: "label_supplier_refund_rate",
          width: 110,
          formatter: (r, c, v, i) => (v ? this.$addUnit(v, "%") : "-"),
        },
        {
          key: "replacementRate",
          label: "label_supplier_replacement_rate",
          width: 110,
          formatter: (r, c, v, i) => (v ? this.$addUnit(v, "%") : "-"),
        },
        {
          key: "defectiveRate",
          label: "label_supplier_defective_percentage",
          width: 110,
          formatter: (r, c, v, i) => (v ? this.$addUnit(v, "%") : "-"),
        },
        {
          key: "supplyTime",
          label: "label_supplier_time_delivery",
          width: 110,
          formatter: (r, c, v, i) => (v ? this.$addUnit(v, "天") : "-"),
        },
        // {
        //   key: "supplierSkuCount",
        //   label: "供货商品数",
        //   width: 110,
        //   formatter: (r, c, v, i) => (v ? v : "-"),
        // },
        // {
        //   key: "purchaseOrderCount",
        //   label: "采购次数",
        //   width: 110,
        //   formatter: (r, c, v, i) => (v ? v : "-"),
        // },
        {
          key: "gmtCreate",
          label: "label_time",
          width: 170,
          render: (h, { row, column }) => {
            return (
              <div>
                <div>
                  {this.$t("label_create")}:{this.$dateFormat(row["gmtCreate"])}
                </div>
                <div>
                  {this.$t("label_update")}:{this.$dateFormat(row["gmtModify"])}
                </div>
              </div>
            );
          },
        },

        {
          type: "operate",
          width: 150,
          operate: [
            {
              label: "label_edit",
              auth: 'oms_purchase_supplier_edit',
              if: this.isEditShow,
              click: (row) => {
                this.$router.push({
                  path: "/page/oms/purchase/supplyManage/supplier_operation",
                  query: { emitKey, edit: true, id: row.id },
                });
              },
            },
            {
              label: "label_delete",
              auth: 'oms_purchase_supplier_edit',
              type: "confirm-button",
              urlType: "json",
              url: '/oms-api/purchase/OmsPurchaseSupplierRpc/delete.json',
              message: 'label_fms_bank_card_confirm_delete',
              params: (v) => {
                return {id: v.id}
              },
              done: ['reload', 'tip']
            },
            {
              label: "label_detail",
              // auth: 'oms_purchase_supplier_edit',
              // if: this.isEditShow,
              click: (row) => {
                this.$router.push({
                  path: "./supplier_manage_detail",
                  query: { emitKey, id: row.id },
                });
              },
            },

            {
              type: "more",
              items: [

              ],
            },
          ],
        },
      ];
    },
    uploadExcelSuccess(response, file, fileList) {
      if (response.code == 0) {
        this.$message.success(this.$tt('label_upload_success'));
        this.$emitPage("oms>import_manage", 'reload')
        this.$confirm(this.$tt("tip_importing_confirm_goto_recode_list"), this.$tt('label_tip'), {
          type: 'success'
        }).then(() => {
          this.$router.push({
            path: '/page/oms/report/import_manage',
          });
        }).catch(() => {

        });
      } else {
        this.$message.error(response.message || this.$tt('label_upload_fail'));
      }
      if (this.$refs.upload) this.$refs.upload.clearFiles()
    },
    uploadExcelError(response, file, fileList) {
      this.$message.error(this.$tt('label_upload_error'))
    },
    exportExcel() {
      const searchParams = this.$refs.SuperTablePage.getSearchData()
      let idList = []
      if (this.selection) {
        idList = this.selection.map(item => item.id)
      }
      let params = {...searchParams,idList }
      this.$functionCommon({
        url: "/oms-api/purchase/OmsPurchaseSupplierRpc/exportExcel.json",
        data: params, type: 'form',
      })
      // business_function.confirmOperateBaseSelectOrForm.call(this, {
      //   data: {...searchParams,idList },
      //   model: this.option.search.model,
      //   mustData: true,
      //   callback: (selection, data) => {
      //     let params = data
      //     this.$functionCommon({
      //       url: "/oms-api/purchase/OmsPurchaseSupplierRpc/exportExcel.json",
      //       data: params, type: 'form',
      //     })
      //   }
      // })

    },
  },
};
</script>
<style></style>
